package com.zhang.exceltest.modules.excel;


import com.zhang.exceltest.modules.sys.dao.SysUserRepository;
import com.zhang.exceltest.modules.sys.entity.SysUser;
import com.zhang.exceltest.modules.common.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@org.springframework.stereotype.Controller
public class Controller {

    @Autowired
    SysUserRepository sysUserRepository;

    @Autowired
    ExcelService<SysUser> excelService;


    @RequestMapping("/export")
    public ModelAndView export(HttpServletRequest request){
        List<SysUser> users = sysUserRepository.findAll();
        return excelService.exportXls(request,users, SysUser.class,"这是一个标题");
    }

    @RequestMapping("/import")
    public void importExcelData(HttpServletRequest request, HttpServletResponse response){
        System.out.println(excelService.doParseExcel(request, response, SysUser.class));
    }

}
